package com.ht.medicaltreatment.adapter

import android.text.TextUtils
import android.widget.CheckBox
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.bean.ConsumableSampleData

class ConsumableSampleListAdapter : BaseQuickAdapter<ConsumableSampleData,BaseViewHolder>(R.layout.item_consumable_sample_layout){

    override fun convert(holder: BaseViewHolder, item: ConsumableSampleData) {
        holder.setText(R.id.tvName,item.name)
        holder.setText(R.id.rfid,item.rfidCode)
        holder.setText(R.id.tvSampleBoxName,item.batchentryRfidSampleBoxName)
        holder.setText(R.id.tvCode,"条形码ID: "+item.barCode)
        holder.setText(R.id.tvLocation,"位置信息： ${item.position}")

        val checkbox = holder.getView<CheckBox>(R.id.checkbox)
        checkbox.isChecked = item.isChecked

        if(!TextUtils.isEmpty(item.rfidCode)){
            holder.setText(R.id.tvState,"已绑定")
            holder.setBackgroundResource(R.id.tvState,R.drawable.shape_sample_item_state_green)
            checkbox.isEnabled = false
        }else{
            holder.setText(R.id.tvState,"未绑定")
            checkbox.isEnabled = true
            holder.setBackgroundResource(R.id.tvState,R.drawable.shape_sample_item_state_gray)
        }
    }
}
